package chixing.day13.homework.work2;

import java.util.ArrayList;
import java.util.HashSet;

public class UserArrayList  {
    private static UserArrayList userArrayList;
    private static ArrayList<User> userList = new ArrayList<>();
    private static HashSet<String> emailSet = new HashSet<>();//只负责接受email，

    private UserArrayList() {

    }

    public static UserArrayList getUserArrayList(){
        if (userArrayList == null) {
            userArrayList = new UserArrayList();
        }
        return userArrayList;
    }


    //添加用户
    public void addUser(User user){
        if (emailSet.contains(user.getUserEmail())){
            System.out.println("邮箱已经存在！！");
        }else {
            userList.add(user);
        }
        emailSet.add(user.getUserEmail());
    }

    public void display(){
        for (User u:userList) {
            System.out.println(u);
        }
    }
}
